/*
 * 2.5.cpp
 *
 *  Created on: 2012-5-17
 *      Author: jawinton
 */


#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main (void) {
	int t[6];
	while (true) {
		cin >> t[0] >> t[1] >> t[2] >> t[3] >> t[4] >> t[5];
		if (t[1] == 0 && t[2] == 0 && t[3] == 0 &&
			t[4] == 0 && t[5] == 0 && t[0] == 0) return 0;
		int total = 0;
		int rest[2]={0,0};

		//t6
		total += t[5];

		//t5
		total += t[4];

		//t4
		total += t[3];
		rest[1] += 5 * t[3];

		//t3
		total += (t[2]+3)/4;;
		int left4 = t[2]%4;
		if (left4 == 1) {
			rest[1] += 5;
		} else if (left4 == 2) {
			rest[1] += 3;
		} else if (left4 == 3) {
			rest[1] += 1;
		}

		//t2
		if (rest[1] < t[1]) {
			total += (t[1]-rest[1]+8)/9;
		}

		//t1
		rest[0] = 36*total - 36*t[5] - 25*t[4] - 16*t[3] - 9*t[2] - 4*t[1];
		if(rest[0] < t[0]) total += (t[0] - rest[0] + 35)/36;
		cout << total << endl;
	}
	return 0;
}
